package convertutil

import (
	"bytes"
	"encoding/base64"
	"github.com/boombuler/barcode"
	"github.com/boombuler/barcode/qr"
	"image/png"
)

// StrToBase64Img 将str的内容转换成base64格式图片
func StrToBase64Img(content string) string {
	if content == "" {
		return ""
	}
	img, _ := qr.Encode(content, qr.M, qr.Auto)
	img, _ = barcode.Scale(img, 256, 256)
	buf := bytes.NewBuffer(make([]byte, 0, 0))
	_ = png.Encode(buf, img)
	base64Img := "data:image/png;base64," + base64.StdEncoding.EncodeToString(buf.Bytes())
	return base64Img
}
